package com.example.myapplication;

import com.google.gson.annotations.SerializedName;

/**
 * 版本信息数据模型
 */
public class VersionInfo {
    
    @SerializedName("version")
    private String version;
    
    @SerializedName("versionCode")
    private int versionCode;
    
    @SerializedName("downloadUrl")
    private String downloadUrl;
    
    @SerializedName("url")
    private String url; // 新API格式中的url字段
    
    @SerializedName("updateContent")
    private String updateContent;
    
    @SerializedName("updateDesc")
    private String updateDesc; // 新API格式中的updateDesc字段
    
    @SerializedName("updateTime")
    private String updateTime; // 更新时间字符串
    
    @SerializedName("updateTimeMs")
    private long updateTimeMs; // 更新时间戳
    
    @SerializedName("forceUpdate")
    private boolean forceUpdate;
    
    @SerializedName("fileSize")
    private long fileSize;
    
    @SerializedName("md5")
    private String md5;
    
    public String getVersion() {
        return version;
    }
    
    public void setVersion(String version) {
        this.version = version;
    }
    
    public int getVersionCode() {
        return versionCode;
    }
    
    public void setVersionCode(int versionCode) {
        this.versionCode = versionCode;
    }
    
    public String getDownloadUrl() {
        // 优先使用url字段，如果没有则使用downloadUrl
        String result = url != null && !url.isEmpty() ? url : downloadUrl;
        // 如果都是null或空，返回null
        return (result != null && !result.isEmpty()) ? result : null;
    }
    
    public void setDownloadUrl(String downloadUrl) {
        this.downloadUrl = downloadUrl;
    }
    
    public String getUrl() {
        return url;
    }
    
    public void setUrl(String url) {
        this.url = url;
    }
    
    public String getUpdateContent() {
        // 优先使用updateDesc字段，如果没有则使用updateContent
        return updateDesc != null && !updateDesc.isEmpty() ? updateDesc : updateContent;
    }
    
    public void setUpdateContent(String updateContent) {
        this.updateContent = updateContent;
    }
    
    public String getUpdateDesc() {
        return updateDesc;
    }
    
    public void setUpdateDesc(String updateDesc) {
        this.updateDesc = updateDesc;
    }
    
    public String getUpdateTime() {
        return updateTime;
    }
    
    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }
    
    public long getUpdateTimeMs() {
        return updateTimeMs;
    }
    
    public void setUpdateTimeMs(long updateTimeMs) {
        this.updateTimeMs = updateTimeMs;
    }
    
    public boolean isForceUpdate() {
        return forceUpdate;
    }
    
    public void setForceUpdate(boolean forceUpdate) {
        this.forceUpdate = forceUpdate;
    }
    
    public long getFileSize() {
        return fileSize;
    }
    
    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }
    
    public String getMd5() {
        return md5;
    }
    
    public void setMd5(String md5) {
        this.md5 = md5;
    }
    
    /**
     * 格式化文件大小
     */
    public String getFormattedFileSize() {
        if (fileSize < 1024) {
            return fileSize + " B";
        } else if (fileSize < 1024 * 1024) {
            return String.format("%.2f KB", fileSize / 1024.0);
        } else {
            return String.format("%.2f MB", fileSize / (1024.0 * 1024.0));
        }
    }
}

